package com.zhangjun.work5.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;


/**
 * @author 张钧
 * @Description
 * @create 2022-09-27 17:16
 */
@Configuration
public class DatabaseConfiguration {
    @Value("jdbc:mysql://localhost:3307/spring")
    private String url;

    @Value("root")
    private String username;

    @Value("123456")
    private String password;

    @Value("com.mysql.cj.jdbc.Driver")
    private String driverClassName;

    @Bean
    public DruidDataSource druidDataSource(){
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setUsername(username);
        druidDataSource.setPassword(password);
        druidDataSource.setUrl(url);
        druidDataSource.setDriverClassName(driverClassName);
        return druidDataSource;
    }

    @Bean
    public DataSourceTransactionManager dataSourceTransactionManager(DruidDataSource druidDataSource){
        return new DataSourceTransactionManager(druidDataSource);
    }
}
